#include "Blocks/RyeBlock.h"
#include "Blocks/SeedsBlock.h"
#include "Blocks/ExperienceBlock.h"

namespace PocketSurvival
{
    void RyeBlock::getCreativeValues(std::vector<int32_t> &blockVec)
    {
        blockVec.push_back(Terrain::MakeBlockValue(Index(), 0, SetIsWild(SetSize(0, 7), true)));
        blockVec.push_back(Terrain::MakeBlockValue(Index(), 0, SetIsWild(SetSize(0, 1), false)));
        blockVec.push_back(Terrain::MakeBlockValue(Index(), 0, SetIsWild(SetSize(0, 3), false)));
        blockVec.push_back(Terrain::MakeBlockValue(Index(), 0, SetIsWild(SetSize(0, 5), false)));
        blockVec.push_back(Terrain::MakeBlockValue(Index(), 0, SetIsWild(SetSize(0, 7), false)));
    }

    void RyeBlock::getDropValues(int32_t oldValue, int32_t newValue, int32_t toolLevel, std::vector<BlockDropValue> &dropValues)
    {
        int32_t num = 0;
        int32_t data = 0;
        int32_t data2 = Terrain::ExtractData(oldValue);
        int32_t size = GetSize(data2);
        bool isWild = GetIsWild(data2);
        if (isWild)
        {
            num = (size > 2 && m_random.getFloat(0.0f, 1.0f) < 0.33f) ? 1 : 0;
            data = 4;
        }
        else
        {
            switch (size)
            {
            case 5:
                num = 1;
                data = 4;
                break;
            case 6:
                num = m_random.getInt(1, 2);
                data = 4;
                break;
            case 7:
                num = m_random.getInt(1, 3);
                data = 5;
                break;
            }
        }
        for (int32_t i = 0; i < num; i++)
        {
            dropValues.emplace_back(Terrain::MakeBlockValue(SeedsBlock::Index(), 0, data), 1);
        }
        if (size == 7 && isWild == false && m_random.getBool(0.5f))
        {
            dropValues.emplace_back(ExperienceBlock::Index(), 1);
        }
    }

    const std::vector<BoundingBox> &RyeBlock::getCustomCollisionBoxes(int32_t value)
    {
        return BlockConstans::defaultCollisionBoxes;
    }

    int32_t RyeBlock::getIndex()
    {
        return Index();
    }
    const std::string &RyeBlock::getBlockName()
    {
        static std::string blockName = "RyeBlock";
        return blockName;
    }

} // namespace PocketSurvival
